package com.leather.market.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.leather.common.entity.Goods;
import com.leather.market.vo.GoodsQueryVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
*  @author kevin
*/
public interface GoodsMapper extends BaseMapper<Goods> {

    /**
     * 二手市场首页需要的数据
     * @param pageId
     * @return
     */

    @Select("select a.*,b.nick_name,b.img_url from goods a,user b \n" +
            "where a.user_id = b.id and a.flag = 0  order by a.create_time desc limit #{pageId},10")
    List<GoodsQueryVo> index(@Param("pageId") int pageId);


    /**
     * 用户的收藏夹
     * @param userId
     * @return
     */

    @Select("select a.*,b.nick_name,b.img_url from goods a,user b\n" +
            "where a.user_id = b.id and  a.id in (select goods_id from goods_car\n" +
            "where user_id = #{userId}) order by a.create_time desc")
    List<GoodsQueryVo> userCollection(@Param("userId") int userId);


    @Select("select a.*,b.nick_name,b.img_url from goods a,user b \n" +
            "where a.user_id = b.id and a.flag = 0 and (a.goods_name like concat('%',#{searchValue},'%') or a.goods_desc like concat('%',#{searchValue},'%') )  order by a.create_time desc")
    List<GoodsQueryVo> search(@Param("searchValue") String searchValue);


    @Select("select a.*,b.nick_name,b.img_url from goods a,user b \n" +
            "where a.user_id = b.id and a.flag = 0 and a.goods_type_id = #{typeId} order by a.create_time desc")
    List<GoodsQueryVo> getByType(@Param("typeId") int typeId);


}